<?php
namespace app\cms\controller;

use app\common\controller\Front;

class Tags extends Front
{
    private $info = [];
    
    private $items = [];
    
    public function _initialize()
    {
        parent::_initialize();
    }
    
    public function index()
    {
        return $this->common('index');
    }
    
    public function _empty($action='')
    {
        //允许的操作名
        if(!in_array($action,explode(',',config('cms.action_name')))){
            $this->error(lang('cmsErrorParams'));
        }
        //默认加载
        return $this->common($action);
    }
    
    private function common($action='index')
    {
        $this->info['pageNumber']     = $this->site['page'];
        $this->info['pageSize']       = intval(config('cms.limit_tags_'.$action));
        $this->info['pagePath']       = DcUrl('cms/tags/'.$action,['pageNumber'=>'[PAGE]']);
        //TKD
        $this->info['seoTitle']       = cmsSeo(lang(camelize('cms_title_tags_'.$action)),$this->site['page']);
        $this->info['seoKeywords']    = cmsSeo(lang(camelize('cms_keywords_tags_'.$action)),$this->site['page']);
        $this->info['seoDescription'] = cmsSeo(lang(camelize('cms_description_tags_'.$action)),$this->site['page']);
        //分页列表
        if($this->info['pageSize']){
            $this->items = cmsTagSelect([
                'cache'   => true,
                'status'  => 'normal',
                'action'  => $action,
                'simple'  => cmsValue(config('cms.total_tags_'.$action)),
                'sort'    => DcEmpty(config('cms.sort_tags_'.$action),'term_count'),
                'order'   => 'desc',
                'paginate'=> [
                    'list_rows' => $this->info['pageSize'],
                    'page'      => $this->site['page'],
                    'path'      => $this->info['pagePath'],
                ]
            ]);
        }
        //变量赋值
        $this->assign($this->info);
        //分页赋值
        $this->assign($this->items);
        //加载模板
        return $this->fetch();
    }
}